package cn.lingyangwl.agile.dynamic.config.remote;

import cn.lingyangwl.agile.model.enums.ConfigDefineEnum;
import cn.lingyangwl.agile.model.module.config.ConfigInfo;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.framework.core.response.RetOps;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.Future;

/**
 * @author shenguangyang
 */
@Service
@ConditionalOnClass({FeignAutoConfiguration.class})
public class ConfigManageApiCloudImpl implements ConfigManageApi {
    @Resource
    @Lazy
    private RemoteConfigManage service;

    @Override
    @Async("myTaskScheduler")
    public Future<ConfigInfo> getUseConfig(ConfigDefineEnum configDefine) {
        Resp<ConfigInfo> resp = service.getUseConfig(configDefine.name());
        RetOps.of(resp).assertSuccess(e -> new BizException(e.getCode(), e.getMsg()));
        return new AsyncResult<>(resp.getData());
    }
}
